# 用于跨模块存取数据

import time
import cv2
import numpy as np

storage_region_data={}
storage_region_pos_only={}

def storage_a_region(x1,x2,y1,y2,name):
    global storage_region_data
    global storage_region_pos_only
    storage_region_data[name] = [x1,x2,y1,y2]
    storage_region_pos_only[name] = [x1,x2,y1,y2]

# 为了在特殊情况下找向箭头按钮, 只存位置, 在使用时也只取位置,避开图像裁剪运算
def storage_a_region_pos_only(x1,x2,y1,y2,name):
    global storage_region_pos_only
    storage_region_pos_only[name] = [x1,x2,y1,y2]

# 只取坐标:
def get_region_pos_only(name):
    # return 如果name不存在, 则返回None
    global storage_region_pos_only
    if name in storage_region_pos_only:
        return storage_region_pos_only[name]
    else:
        return None

# 按钮的中心坐标
def get_button_cention(name):
    # return 按钮的中心坐标 如果name不存在, 则返回None
    result1 = get_region_pos_only(name)
    if result1 == None:
        return None
    return [(result1[0]+result1[1])/2,(result1[2]+result1[3])/2]
    

# @return [x1,x2,y1,y2]
def get_region(name):
    global storage_region_data
    return storage_region_data[name]

def get_screen_clips(frame):
    # for i in storage_region_data:
    #     print(f"# 16 \t {i}:{storage_region_data[i]}")

    obj_result_screen_shot_clip = {}
    for i in storage_region_data:
        obj_result_screen_shot_clip[i] = frame[storage_region_data[i][2]:storage_region_data[i][3], storage_region_data[i][0]:storage_region_data[i][1]]

    return obj_result_screen_shot_clip

def get_screen_clips_len():
    return len(storage_region_data)

